﻿// Type: D2L.Extensibility.AuthSdk.D2LWebException
// Assembly: D2L.Extensibility.AuthSdk, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null
// MVID: B2FBA42B-591C-474F-A782-6FF215FEDFB9
// Assembly location: C:\Users\leandro.perdizo\Desktop\D2L.Extensibility.AuthSdk.dll

using System.IO;
using System.Net;
using System.Text;

namespace D2L.Extensibility.AuthSdk
{
  public class D2LWebException
  {
    private readonly HttpStatusCode m_statusCode = HttpStatusCode.NotImplemented;
    private readonly string m_responseBody = "";

    public virtual HttpStatusCode StatusCode
    {
      get
      {
        return this.m_statusCode;
      }
    }

    public virtual string ResponseBody
    {
      get
      {
        return this.m_responseBody;
      }
    }

    public D2LWebException(WebException ex)
    {
      if (ex == null)
        return;
      HttpWebResponse httpWebResponse = ex.Response as HttpWebResponse;
      if (httpWebResponse == null)
        return;
      this.m_statusCode = httpWebResponse.StatusCode;
      using (Stream responseStream = httpWebResponse.GetResponseStream())
      {
        if (responseStream == null)
          return;
        using (StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8))
          this.m_responseBody = streamReader.ReadToEnd();
      }
    }
  }
}
